package jsen.tool.ddd.adapter.infrastructure.specification.base;

import jsen.tool.ddd.adapter.infrastructure.specification.ISpecification;

/**
 * @author jsen
 * @date 2021/10/8
 */
class SdlNode<T> {
    private final SdlSpecificationSupplier factory;

    private String word;
    private ISpecification<T> specification;


    public SdlNode(SdlSpecificationSupplier factory, String word) {
        this.factory = factory;
        this.word = word;
    }

    public SdlNode(SdlSpecificationSupplier factory, ISpecification<T> specification) {
        this.factory = factory;
        this.specification = specification;
    }

    public boolean isLeft() {
        return "(".equals(word);
    }

    public boolean isRight() {
        return ")".equals(word);
    }

    public boolean isOr() {
        return "or".equalsIgnoreCase(word);
    }

    public boolean isAnd() {
        return "and".equalsIgnoreCase(word);
    }

    public ISpecification<T> getSpecification() {
        if (specification != null) {
            return specification;
        }
        this.specification = factory.getSpec(word);
        return specification;
    }
}
